/*
 *  NFCSigning - Open source library for signing/validation of NDEF messages
 *  Copyright (C) 2009-2010 The NFCSigning Team
 *
 *  This library is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU Lesser General Public
 *  License as published by the Free Software Foundation; either
 *  version 2.1 of the License, or (at your option) any later version.
 *
 *  This library is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *  Lesser General Public License for more details.
 *
 *  You should have received a copy of the GNU Lesser General Public
 *  License along with this library; if not, write to the Free Software
 *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 *
 */
package my.javax.microedition.contactless.ndef;

import org.nfcsigning.jsr257.impl.NDEFMessageImpl;

/**
 *
 * @author emarkki
 */
public class NDEFRecord {
    private NDEFRecordType recordType;
    private byte[] id;
    private byte[] payload;

    public NDEFRecord(byte[] data, int offset) {
        NDEFMessage msg = new NDEFMessage(data, offset);
        this.recordType = msg.getRecord(0).getRecordType();
        this.id = msg.getRecord(0).getId();
        this.payload = msg.getRecord(0).getPayload();
    }

    public NDEFRecord(NDEFRecordType recordType, byte[] id, byte[] payload) {
        this.recordType = recordType;
        this.id = id;
        this.payload = payload;
    }

    public byte[] getId() {
        return id;
    }

    public NDEFMessage getNestedNDEFMessage(int offset) {
        return new NDEFMessage(payload, offset);
    }

    public byte[] getPayload() {
        return payload;
    }

    public int getPayloadLength() {
        return payload.length;
    }

    public byte[] toByteArray() {
        return NDEFMessageImpl.toRecordByteArray(this);
    }

    public NDEFRecordType getRecordType() {
        return recordType;
    }
    
}
